package com.wwz.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wwz.entity.Result;
import com.wwz.entity.User;
import com.wwz.query.UserQuery;
import com.wwz.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("user")
@Api(tags = "用户控制器")
public class UserController {

    @Resource
    private IUserService userService;

    @GetMapping("toPage")
    @ApiOperation("用户列表")
    public Result toPage(UserQuery query){
        IPage<User> iPage = userService.toPage(query);
        return Result.ok(iPage);
    }

    @PostMapping("addOrUpData")
    @ApiOperation("添加或修改")
    public Result addOrUpData(@RequestBody User user){
        userService.addOrUpData(user);
        return Result.ok("操作成功");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除用户")
    public Result deleteById(@PathVariable String id){
        userService.deleteById(id);
        return Result.ok("删除成功");
    }
}
